#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from store.mdb_store import TableStore


class QheeProjectListStore(TableStore):
    def __init__(self, config):
        self.table = config.get('table', 'qhee_project_list')
        self.table_config = {
            'mdb': config['mdb'],
            'table': self.table,
            'column_dic': {
                'applyStatus': "INT NOT NULL DEFAULT '0' COMMENT '应用状态'",
                'updateStatus': "INT NOT NULL DEFAULT '0' COMMENT '更新状态'",
                'followStatus': "INT NOT NULL DEFAULT '0' COMMENT '流状态'",
                'displayLabel': "json COMMENT '显示标记'",
                'similarResultTotal': "INT NOT NULL DEFAULT '0' COMMENT '全部相似结果'",
                'recentApplyResultTotal': "INT NOT NULL DEFAULT '0' COMMENT '全部最近申请结果'",
                'recentApplyResultYear': "INT NOT NULL DEFAULT '0' COMMENT '年内申请结果'",
                'topic': "json COMMENT '主题'",
                'followTime': "varchar(255) NOT NULL DEFAULT '' COMMENT '跟随时间'",
                'attribute': "varchar(255) NOT NULL DEFAULT '' COMMENT '属性'",
                'source': "varchar(255) NOT NULL DEFAULT '0' COMMENT '来源'",
                'project_id': "INT NOT NULL DEFAULT '0' COMMENT '项目ID'",
                'applyTimeDesc': "varchar(255) NOT NULL DEFAULT '' COMMENT '申请时间'",
                'rewardType': "INT NOT NULL DEFAULT '0' COMMENT '奖励类型'",
                'applyTimeType': "INT NOT NULL DEFAULT '0' COMMENT '申请时间类型'",
                'applyResultTotal': "INT NOT NULL DEFAULT '0' COMMENT '全部申请结果'",
                'title': "varchar(255) NOT NULL DEFAULT '' COMMENT '标题'",
                'updateTime': "varchar(255) NOT NULL DEFAULT '' COMMENT '更新时间'",
                'reward': "varchar(255) NOT NULL DEFAULT '' COMMENT '奖励'",
                'historyApplyTime': "json COMMENT '历史申请时间'",
                'sortKey': "INT NOT NULL DEFAULT '0' COMMENT '排序关键字'",
                'matchDetail': "json COMMENT '匹配详情'",
                'publishedTime': "varchar(255) NOT NULL DEFAULT '' COMMENT '发布时间'",
                'areaLabel': "varchar(255) NOT NULL DEFAULT '' COMMENT '地区标签'",
                'rewardTypeDesc': "varchar(255) NOT NULL DEFAULT '' COMMENT '奖励类型'",
                'upDownTime': "varchar(255) NOT NULL DEFAULT '' COMMENT ''",
                'outline': "varchar(255) NOT NULL DEFAULT '' '概述'",
                'direction': "varchar(255) NOT NULL DEFAULT '' '方向'",
                'institution': "varchar(255) NOT NULL DEFAULT '' '制度'",
                'institutionLevel': "varchar(255) NOT NULL DEFAULT '' '制度等级'",
                'declareStatus': "INT NOT NULL DEFAULT '0' COMMENT ''",
                'isStatus': "INT NOT NULL DEFAULT '0' COMMENT ''",
                'declareStatusLabel': "varchar(255) NOT NULL DEFAULT '' ''",
                'similarApplyResultTotal': "INT NOT NULL DEFAULT '0' COMMENT ''",
                'similarApplyResultYear': "INT NOT NULL DEFAULT '0' COMMENT ''",
                'matchingDegree': "INT NOT NULL DEFAULT '0' COMMENT ''",
                'publishTimeStatus': "INT NOT NULL DEFAULT '0' COMMENT ''",
                'timeDesc': "varchar(255) NOT NULL DEFAULT '' ''",
                'applyDesc': "varchar(255) NOT NULL DEFAULT '' ''",

            },
            'uniq_idx_fields': ['project_id'],
            'idx_dic': {
                '{0}_name_idx'.format(self.table): ['title']
            },
            'dump_fields': [
                'displayLabel', 'topic', 'historyApplyTime', 'matchDetail'
            ],
            # 'text_fields': [
            #     'displayLabel', 'topic', 'historyApplyTime', 'matchDetail'
            # ]
        }
        super(QheeProjectListStore, self).__init__(self.table_config)


class QheeProjectStore(TableStore):
    def __init__(self, config):
        self.table = config.get('table', 'qhee_project')
        self.table_config = {
            'mdb': config['mdb'],
            'table': self.table,
            'column_dic': {
                'project_id': "INT NOT NULL DEFAULT '0' COMMENT '项目ID'",
                'name': "varchar(255) NOT NULL DEFAULT '' COMMENT '项目名称'",
                'reward_way': "varchar(50) NOT NULL DEFAULT '' COMMENT '奖励方式'",
                'declare_time': "varchar(50) NOT NULL DEFAULT '' COMMENT '申报时间'",
                'company_name': "varchar(50) NOT NULL DEFAULT '' COMMENT '实施机构'",
                'successful_declaration': "text NOT NULL COMMENT '申报成功可能性'",
                'original_policy': "varchar(255) NOT NULL DEFAULT '' COMMENT '政策原文'",
                'original_link': "varchar(255) NOT NULL DEFAULT '' COMMENT '原文链接'",
                'standard': "text NOT NULL COMMENT '支持标准'",
                'reporting_requirements': "text NOT NULL COMMENT '申报要求'",
                'standard_content': "text NOT NULL COMMENT '支持内容'",
                'requirements': "text NOT NULL COMMENT '具体要求'",
                'materials': "text NOT NULL COMMENT '材料清单'",
                'procedure': "text NOT NULL COMMENT '办理程序'",
                'according_to': "text NOT NULL COMMENT '设定依据'",
                'download_attachment': "text NOT NULL COMMENT '附件下载'",
                'attention_info': "text NOT NULL COMMENT '注意事项'",
                'successful_declaration_table': "json COMMENT '申报成功可能性表格内容'",
            },
            'uniq_idx_fields': ['project_id'],
            'idx_dic': {
                '{0}_name_idx'.format(self.table): ['name', 'company_name']
            },
            'update_fields': [
                'name', 'reward_way', 'company_name', 'original_policy', 'original_link', 'standard',
                'reporting_requirements', 'materials', 'procedure', 'according_to', 'download_attachment',
                'successful_declaration_table', 'standard_content', 'requirements'
            ],
            'text_fields': [
                'standard', 'materials', 'download_attachment', 'successful_declaration', 'reporting_requirements',
                'procedure', 'according_to', 'attention_info', 'standard_content', 'requirements'
            ],
            'dump_fields': [
                'successful_declaration_table', 'download_attachment',
            ]
        }
        super(QheeProjectStore, self).__init__(self.table_config)
